<%@page import="java.awt.print.Printable"%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
<title>_${customer.customerName}_作业批次</title>


<script type="text/javascript">
	var datatable_content;
	var filterParam={};
	var flg="";//标示 是点击搜索的数据（Y），还是页面导向的数据(N)
	 $(function() {
		$("#queryForm").validate();
		$("#_fromDate").datepicker({ format:'yyyy-mm-dd'});
		$("#_toDate").datepicker({ format:'yyyy-mm-dd'});
		flg="N";
		initTable();
	 });

	
	function initTable(){
	datatable_content = $("#contentTable").dataTable({
		   "bServerSide":true,
		   "bAutoWidth":false,
           "sAjaxSource":'${ctx}/workBatch/v2_queryWorkBatch',
           "fnServerData": callback,
           "fnRowCallback":rowCallBack,
           "bFilter": false,
           "bSort": false,
           "sZeroRecords": "查询无记录！",
           "bProcessing": true,
           "oLanguage": {
               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
            },
             "aoColumns":[
             	 {"mData": null},
             	 {"mData": 'customer',
                	 "render": function (obj) {
                         return obj==null?'':obj.customerName;
                      }
                 },
                 {"mData": 'warehouse',
                	 "render": function (obj) {
                         return obj==null?'':obj.groupName;
                      }
                 },
             	{"mData": 'batchCode',
               	 "render": function (obj) {
                        return "<a href='${ctx}/workMsg/v2_workMsgDetail/" + obj + "'>"+ obj +"</a>";
                     }
                },
                {"mData": 'prioritySendFlag',
                	"render": function (obj) {
                        return obj=="1" ? "是":"否";
                     }
                },
             	 {"mData": null},
             	 {"mData": null},
             	 {"mData": null},
             	 {"mData": "orderQty"},
             	 {"mData": "creater.realname"},
             	 {"mData": 'createTime',
                	 "render": function (obj) {
                    	  var time=obj.time;
                         var date = new Date(time);
                         return date.Format("yyyy-MM-dd hh:mm");
                      }
               	 },
             	 {"mData": null},
             	 {"mData": null},
             ],
             "aoColumnDefs":[
             	{"aTargets": [5],
	              "mRender": function (data, display, row) {
						return row.pickType == "single" ? "单件":
							   row.pickType == "multi" ? "多件" : "";
		           }
	            },
	            {"aTargets": [6],
		              "mRender": function(data,display,row){
		              		return row.billType == "cbill" ? "普通运单":
		              			   row.billType == "ebill" ? "电子运单" : "";
		              }
		            },
	            {"aTargets": [7],
	              "mRender": function(data,display,row){
	              		return row.flowType == "prePrint" ? "预先打单":
	              			   row.flowType == "intimePrint" ? "及时打单" : "";
	              }
	            },
	            {"aTargets": [11],
	              "mRender": function(data,display,row){
	              		return row.status == "1" ? "已创建批次":
	              			   row.status == "2" ? "已创建任务":
	              			   row.status == "3" ? "已拣货":
	              			   row.status == "4" ? "已包装":
	              			   row.status == "5" ? "已发货": "";
	           	   }
	            },
	            
	             {"aTargets": [12],
	              "mRender": function(data,display,row){
	              		var rs = "";
	              		if(row.status == "1"){
	              			rs += "<a href='${ctx}/workTask/v2_toCreateWorkTask/"+ row.batchCode +"' role='button'  class='btn btn-primary' >创建作业任务</a>";
	              		}else{
	              			rs += "<a href='${ctx}/workTask/v2_toCreateWorkTask/"+ row.batchCode +"' role='button'  class='btn btn-info' >查看作业任务</a>";
	              		}
	              		rs +=" <a href='${ctx}/workBatch/exportExcelGY/"+ row.batchCode +"' role='button'  class='btn btn-primary' >管易</a>";
	              		return rs;
	           	   }
	            },
             ]
		});
	}
	function callback(sSource, aoData, fnCallback ) {

	   aoData.push( { "name": "customerCode", "value": $("#_customerCode").val() } );  
	   aoData.push( { "name": "warehouseCode", "value": $("#_warehouseCode").val() } );
	   aoData.push( { "name": "fromDate", "value": $("#_fromDate").val() } );
	   aoData.push( { "name": "toDate", "value": $("#_toDate").val() } );
	   aoData.push( { "name": "pickType", "value": $("#_pickType").val() } );
	   aoData.push( { "name": "status", "value": $("#_status").val() } );
	   aoData.push( { "name": "flg", "value": flg } );
	   aoData.push( { "name": "psFlag", "value": $("#_psFlag").val() } );
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": fnCallback  
	   });
	}
	
	/**
	*创建了行的回调
	*nRow为当前的tr
	*/
	function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
		var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
		$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
	}
	

	function query() {
		if ($("#queryForm").valid()) {
			if (datatable_content) {
				datatable_content.fnDestroy();
			}
			flg="Y";
			initTable();
		}
	}
</script>
</head>

<body>


<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">条件查询</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
				
				
    <%-- <form class="form-search" id="queryForm" method="post" action="${ctx}/workBatch/v2_queryWorkBatch" style="margin-top: 10px;"> --%>
    <form class="form-search" id="queryForm" method="post"  style="margin-top: 10px;">
<!-- 	<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;"> -->
<!-- 		<thead> -->
<!-- 			<th style="vertical-align: middle; color: white; " colspan="1" bgcolor="#8EB4CB">条件查询</th> -->
<!-- 		</thead> -->
<!-- 		<tr > -->
<!-- 		   <td> -->
		   
		   <div class="form-group row">
		   		
		   		<div class="col-sm-3">
					<div class="input-group col-sm-12">
						<span class="input-group-text">商家用户: </span> 
						<select class="form-control"   id="_customerCode" name="_customerCode"  value="${param._customerCode}" onchange="ajaxAreaGroup(this,'_warehouseCode');">
						       <option value=""></option>
								<c:forEach items="${customerList}" var="customer">
									<option value="${customer.customerCode}"
									  <c:if test="${customerCode eq customer.customerCode }">selected=selected</c:if>
									>${customer.customerName}</option>
								</c:forEach>
						 </select> 
					</div>
				</div>
		   


				<div class="col-sm-3">
					<div class="input-group col-sm-12">
						<span class="input-group-text">作业仓库: </span> 
						<select class="form-control"  id="_warehouseCode" name="_warehouseCode" class="input-medium">
							<option value=""></option>
							<c:forEach items="${warehouseList}" var="w">
							   <option value="${w.groupCode}" 
							   <c:if test="${warehouseCode eq w.groupCode }">selected=selected</c:if>
							   >${w.groupName}</option>
						   </c:forEach>
						 </select> 
					</div>
				</div>
				
				
				<div class="col-sm-3">
					<div class="input-group col-sm-12">
						<span class="input-group-text">创建时间:&nbsp;&nbsp; </span> 
						<div class="input-group-addon">
							<i class="fa fa-calendar"></i>
						</div>
						<input type="text" name="_fromDate" id="_fromDate"  class="form-control" value="${fromDate}">
					</div>
				</div>
				
				
				<div class="col-sm-3">
					<div class="input-group col-sm-12">
						<span class="input-group-text">至:&nbsp;&nbsp; </span> 
						<div class="input-group-addon">
							<i class="fa fa-calendar"></i>
						</div>
						<input type="text" name="_toDate" id="_toDate" class="form-control" value="${toDate}" >
					</div>
				</div>
				
			</div>    
<!-- 		   </td> -->
<!-- 		</tr> -->
<!-- 		<tr><td> -->
		
			<div class="form-group row">
		
				<div class="col-sm-3">
					<div class="input-group col-sm-12">
						<span class="input-group-text">订单类型: </span> 
						<select class="form-control" id="_pickType" name="_pickType">
								<option value="" <c:if test="${pickType eq ''}">selected="selected"</c:if>>全选</option>
						        <option value="single" <c:if test="${pickType eq 'single'}">selected="selected"</c:if>>单件</option>
						        <option value="multi" <c:if test="${pickType eq 'multi'}">selected="selected"</c:if>>多件</option>
						 </select> 
					</div>
				</div>
				


				<div class="col-sm-3">
					<div class="input-group col-sm-12">
						<span class="input-group-text">批次状态: </span> 
						<select class="form-control"   id="_status" name="_status">
					        <option value="" <c:if test="${status eq ''}">selected="selected"</c:if>>全选</option>
					        <option value="1" <c:if test="${status eq '1'}">selected="selected"</c:if>>已创建批次</option>
					        <option value="2" <c:if test="${status eq '2'}">selected="selected"</c:if>>已创建任务</option>
					        <option value="3" <c:if test="${status eq '3'}">selected="selected"</c:if>>已拣货</option>
					        <option value="4" <c:if test="${status eq '4'}">selected="selected"</c:if>>已包装</option>
					        <option value="5" <c:if test="${status eq '5'}">selected="selected"</c:if>>已发货</option>
						 </select> 
					</div>
				</div>
				
				<div class="col-sm-3">
					<div class="input-group col-sm-12">
						<span class="input-group-text"> 是否优先派送: </span> 
							<select class="form-control"   id="_psFlag" name="_psFlag" >
								<option value="-1"  <c:if test="${psFlag eq '-1'}">selected="selected"</c:if>>全部</option>
							    <option value="0"   <c:if test="${psFlag eq '0'}">selected="selected"</c:if>>否</option>
								<option value="1"  <c:if test="${psFlag eq '1'}">selected="selected"</c:if>>是</option>
							</select>
					</div>
				</div>
				
		


			<div class="col-sm-2">
					<div class="input-group col-sm-12">
						<button class="btn btn-info" type="button" onclick="query();" style="margin-left: 10px;">搜索</button>
						
					</div>
				</div>
				
		
		   
		  </div>
<!-- 		</td></tr> -->
<!-- 	</table> -->
	 </form>
	
	</div>
	</div>
	</div>
	</div>
	
	
	<!-- 查询结果 start -->
	<div class="form-group row" >
	<div class="col-md-12">
	
	<div class="nav-tabs-custom">
	
	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			    <th>序号</th>
			    <th>商家</th>
			    <th>仓库</th>
			    <th>批次</th>
			    <th>是否优先派送</th>
			    <th>拣货类型</th>
			    <th>运单类型</th>
			    <th>作业类型</th>
			    <th>订单数量</th>
			    <th>创建人</th>
			    <th>创建时间</th>
			    <th>批次状态</th>
			    <th>操作</th>
			</tr></thead>
		<tbody>
	<%-- 	<c:forEach items="${workBatchList}" var="workBatch" varStatus="i">
			<tr>
			   <td>${i.count}</td>
			   <td>${workBatch.customer.customerName}</td>
			   <td>${workBatch.warehouse.groupName}</td>
			   <td><a href='${ctx}/workMsg/v2_workMsgDetail/${workBatch.batchCode}'>${workBatch.batchCode}</a></td>
			   <td>
			     <c:if test="${workBatch.pickType eq 'single'}">单件</c:if>
			     <c:if test="${workBatch.pickType eq 'multi'}">多件</c:if>
			   </td>
			   <td>
			     <c:if test="${workBatch.billType eq 'cbill'}">普通运单</c:if>
			     <c:if test="${workBatch.billType eq 'ebill'}">电子运单</c:if>
			  </td>
			  <td>
			     <c:if test="${workBatch.flowType eq 'prePrint'}">预先打单</c:if>
			     <c:if test="${workBatch.flowType eq 'intimePrint'}">即时打单</c:if>
			  </td>
			   <td>${workBatch.orderQty}</td>
			   <td>${workBatch.creater.realname}</td>
			   <td>${fn:substring(workBatch.createTime,0,19)}</td>
			   <td>
			     <!-- 批次状态 (1.已创建批次 2.已创建任务 3.已拣货 4.已包装  5.已发货) -->
			     <c:if test="${workBatch.status eq '1'}">已创建批次</c:if>
			     <c:if test="${workBatch.status eq '2'}">已创建任务</c:if>
			     <c:if test="${workBatch.status eq '3'}">已拣货</c:if>
			     <c:if test="${workBatch.status eq '4'}">已包装</c:if>
			     <c:if test="${workBatch.status eq '5'}">已发货</c:if>
			   </td>
			   <td>
			      <c:if test="${workBatch.status eq '1'}">
			         <a href="${ctx}/workTask/v2_toCreateWorkTask/${workBatch.batchCode}" role="button"  class="btn btn-primary" >创建作业任务</a>
			      </c:if>
			      <c:if test="${workBatch.status ne '1'}">
			         <a href="${ctx}/workTask/v2_toCreateWorkTask/${workBatch.batchCode}" role="button"  class="btn btn-info" >查看作业任务</a>
			      </c:if>
			      <a href="${ctx}/workBatch/exportExcelGY/${workBatch.batchCode}" role="button"  class="btn btn-primary" >管易</a>
			   </td>
			</tr>
		</c:forEach> --%>
		</tbody>
	</table>
	
	</div>
	
	</div>
    </div>
    
	</section>
</body>
</html>
